package com.docios.cookbook2.ui.adapter;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.docios.cookbook2.ui.homePager.HomeFragment;
import com.docios.cookbook2.ui.homePager.UserFragment;
import com.docios.cookbook2.ui.otherPager.FavoriteFragment;

public class ViewPagerAdapter extends FragmentStateAdapter {
    HomeFragment homeFragment=new HomeFragment();
    FavoriteFragment favoriteFragment=new FavoriteFragment();
    UserFragment userFragment=new UserFragment();
   Bundle bundle;

    /*
    * 自定义构造函数，用于传递bundle数据
    * */
    public ViewPagerAdapter(@NonNull FragmentActivity fragmentActivity,Bundle bundle) {
        super(fragmentActivity);
        this.bundle=bundle;
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        switch (position){
            case 0:
                homeFragment.setArguments(bundle);//假如有需要
                return homeFragment;
            case 1:
                favoriteFragment.setArguments(bundle);//假如有需要
                return favoriteFragment;
            case 2:
                userFragment.setArguments(bundle);
                return userFragment;
        }
        return null;
    }

    @Override
    public int getItemCount() {
        return 3;
    }
}
